package app.framework.freemarker.model;

import freemarker.template.TemplateModelException;
import jasmine.framework.common.util.CheckUtil;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用于引用应用(非第三方库)的样式。
 * </p>
 *
 * @author mh.z
 */
public class AppCssMethodModel extends AbstractResourceMethodModel {

    public AppCssMethodModel() {
        super();
    }

    public AppCssMethodModel(Map<String, String> mappingUrls) {
        super(mappingUrls);
    }

    @Override
    public Object exec(List args) throws TemplateModelException {
        CheckUtil.notNull(args, "args null");

        if (args.size() < 1) {
            return "";
        }

        StringBuilder resultUrl = new StringBuilder();
        String originalUrl = (String) args.get(0);
        String mappedUrl = getMappedUrl(originalUrl);

        resultUrl.append(mappedUrl);
        // URL 后拼接参数防止请求被浏览器缓存
        resultUrl.append("?t=");
        resultUrl.append(System.currentTimeMillis());

        return resultUrl.toString();
    }

}
